class Solution {
public:
    int wateringPlants(vector<int>& nums, int cap)
    {
        int ans = 0;
        int rec = cap;
        int cnt = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            if (cap >= nums[i])
            {
                ans++;
                cnt++;
                cap -= nums[i];
            }
            else
            {
                ans += 2 * cnt + 1;
                cnt++;
                cap = rec;
                cap -= nums[i];
            }
        }
        return ans;
    }
};